Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't update dynamiccssrules on panning, add chromium percentage missing redraw workaround #140

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jonenst
Copy link
Collaborator

@jonenst jonenst commented Dec 13, 2024

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem?
NO

What kind of change does this PR introduce?

feature/bugfix

What is the current behavior?
css rules are updated when the viewbox changes, even for translations. But we only use the zoom level in rules
Also, chromium doesn't update the rendering when of percents (stroke-width), so add a workaround to force redraw
when the zoom changes by 1 percent

What is the new behavior (if this is a feature change)?
no update of rules during translations. Chromium redraw on zoom workaround (enabled all the time for consistency)

Does this PR introduce a breaking change or deprecate an API?

  • Yes
  • No

Other information:

we could split this PR in 2. We could enable the workaround only if we detect dynamic rules with percentages

const previousMaxDisplayedSize = this.getPreviousMaxDisplayedSize();
// in case of bad or unset values NaN or Infinity, this condition is skipped and the function behaves as if zoom changed
if (
Math.abs(previousMaxDisplayedSize - maxDisplayedSize) / previousMaxDisplayedSize <
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

divide by zero

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of bad or unset values NaN or Infinity, this condition is skipped and the function behaves as if zoom changed

Comment on lines 1423 to 1436
//Workaround chromium (tested on edge and google-chrome 131) doesn't
//redraw things with percentages on viewbox changes but it should,
//force it. Firefox does correctly redraw, but we force for everyone to
//have the same behavior everywhere and detect problems more easily.
//we can't use innerHtml+='' on the <style> tags because values set
//with setProperty(key, value) in updateSvgCssDisplayValue are not
//reflected in the html text so the innerHTML trick has the effect of
//resetting them. So instead of doing it on the svg, we do it on all
//its children that are not style elements. This won't work if there
//are deeply nested style elements that need dynamic css rules but in
//practice only the root style element hasdynamic rules so it's ok.
//remove this when chromium fixes their bug if this workaround causes
//problem, we can find a better way to force a redraw that doesnt
//change the elements in the dom
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//Workaround chromium (tested on edge and google-chrome 131) doesn't
//redraw things with percentages on viewbox changes but it should,
//force it. Firefox does correctly redraw, but we force for everyone to
//have the same behavior everywhere and detect problems more easily.
//we can't use innerHtml+='' on the <style> tags because values set
//with setProperty(key, value) in updateSvgCssDisplayValue are not
//reflected in the html text so the innerHTML trick has the effect of
//resetting them. So instead of doing it on the svg, we do it on all
//its children that are not style elements. This won't work if there
//are deeply nested style elements that need dynamic css rules but in
//practice only the root style element hasdynamic rules so it's ok.
//remove this when chromium fixes their bug if this workaround causes
//problem, we can find a better way to force a redraw that doesnt
//change the elements in the dom
//Workaround chromium (tested on edge and google-chrome 131) doesn't
//redraw things with percentages on viewbox changes but it should,
//so we force it. Firefox correctly redraws, but we force it for everyone to
//have the same behavior everywhere and detect problems more easily.
//We can't use innerHtml+='' on the <style> tags because values set
//with setProperty(key, value) in updateSvgCssDisplayValue are not
//reflected in the html text so the innerHTML trick has the effect of
//resetting them. So instead of doing it on the svg, we do it on all
//its children that are not style elements. This won't work if there
//are deeply nested style elements that need dynamic css rules but in
//practice only the root style element has dynamic rules so it's ok.
//Remove this when chromium fixes their bug if this workaround causes
//problem, we can find a better way to force a redraw that doesnt
//change the elements in the dom

@jonenst jonenst changed the title Don't update dynamiccssrules on translations, add chromium workaround Don't update dynamiccssrules on panning, add chromium workaround Dec 13, 2024
@jonenst jonenst changed the title Don't update dynamiccssrules on panning, add chromium workaround Don't update dynamiccssrules on panning, add chromium percentage missing redraw workaround Dec 13, 2024
This allows to see the effect of the workarounds for the css containing percent in the demo.
And it's generally useful to have this kind of css when enabling level of detail

Signed-off-by: HARPER Jon <[email protected]>
Signed-off-by: HARPER Jon <[email protected]>
Signed-off-by: HARPER Jon <[email protected]>
@jonenst jonenst force-pushed the fixsvgpercentwhenzoom branch from 912cebd to 52cdd79 Compare December 17, 2024 09:00
Copy link

sonarcloud bot commented Dec 17, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants